#! /bin/bash

. ./scripts/shell/common.sh
. ./scripts/shell/golang.sh
. ./scripts/shell/tool.sh



PRE_HOOK="./scripts/hooks/pre-build.sh"
END_HOOK="./scripts/hooks/end-build.sh"

if [ -f ${PRE_HOOK} ];then
. ${PRE_HOOK}
fi

if [ -z "${BUILD_TIMES}" ]; then
    BUILD_TIMES=$(date "+%Y%m%d%H%M%S")
fi

printShort "正在计算版本号"

VERSION=`${GSEMVER} bump`

echo "目前版本号为: ${VERSION}-${BUILD_TIMES}"

REPO=`${GIT} remote get-url origin`

NAME=`${GIT} config user.name`
EMAIL=`${GIT} config user.email`

AUTHOR="${NAME}(${EMAIL})"

echo "${YS_CLI} go build -r ${REPO} -a ${AUTHOR} -v ${VERSION}-${BUILD_TIMES}"

${YS_CLI} go build -r ${REPO} -a ${AUTHOR} -v ${VERSION}-${BUILD_TIMES}

# 判断build 结果失败时 不执行hook
if [[ "$?" != 0 ]]
then
    exit 1
fi

if [ -f ${END_HOOK} ];then
. ${END_HOOK}
fi